﻿

<div class="row-fluid">
	<div class="span3">
		<div class="well sidebar-nav">
			<ul class="nav nav-list">
				<li class="nav-header"><?php echo TEAMS_TXT?></li>
				<?php
				$selectedLetter = isset($_GET['letter'])?$_GET['letter']:'all';
				?>
				<br/>
				<li <?php echo ($selectedLetter == 'all' ? "class=\"active\"":"")?>><a href="index.php?site=teams"><?php echo ALL_TEAM_TXT?></a></li>
				<?php
				$selectedLetterId = "";
				include "classes/db/dbmanager.php";
				$pDatabase = Database::getInstance();
				$sql="SELECT distinct l.letter, l.id FROM letters l, team t WHERE t.letterId = l.id ORDER BY l.letter";
				$result = $pDatabase->query($sql);
				if (!$result) {
					die('Error: ' . mysql_error());
				}
				while($row = mysql_fetch_array($result)) {
					echo "<li ".($selectedLetter== $row["letter"] ? "class=\"active\"":"")."><a href=\"index.php?site=teams&letter=".$row["letter"]."\">".$row["letter"]."</a></li>";
					if ($selectedLetter== $row["letter"]) {
						$selectedLetterId = $row["id"];
					}
				}
				?>
			</ul>
		</div>
		<!--/.well -->
	</div>
	
	<!--/span-->
	<div class="span9">
         <?php 
    if ($selectedLetterId > 0) {
    	$sql="SELECT * FROM team WHERE letterId = ".$selectedLetterId." ORDER BY letterId, teamName";
    } else {
		$sql="SELECT * FROM team ORDER BY letterId, teamName";
	}
	
	$result = $pDatabase->query($sql);
	$teamNumber = 0;
	while($row = mysql_fetch_array($result)) {
	if ($teamNumber%3 == 0) {
	?>
	<div class="row-fluid">
	<?php }?>
            <div class="span4">
              <h2><?php echo $row["teamName"]?></h2>
              
		<?php 
		$sqlImage="SELECT * FROM image WHERE teamId = ".$row["id"];
		$resultImage = $pDatabase->query($sqlImage);
		$imageCount = 0;
		while($imageRow = mysql_fetch_array($resultImage)) {?>
		
		<a <?php echo ($imageCount > 0 ? "class=\"hiddenimage\"": "")?> href="<?php echo Config::IMAGE_DIR.$imageRow["imageName"]; ?>" rel="<?php echo "lightbox[images_".$row["id"]."]"?>" title="<?php echo $_SESSION['lang']=='hu' ? $imageRow["imageDesc_hu"] : $imageRow["imageDesc_en"]; ?>"><img src="<?php echo Config::IMAGE_DIR.$imageRow["imageName"]; ?>" rel="lightbox" width="250" height="250"></a>
	 	
            
		
	<?php 
	$imageCount++;
	}?>
	</div>
	<?php 
	if ($teamNumber%3 == 2) {
	?>
          </div>
          
<?php	
	}
	$teamNumber++;
	}
	?>
</div>
<!--/row-->

<hr>
